package com.huike.game.Activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;
import com.huike.game.R;
import com.huike.game.base.Game69;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import androidx.appcompat.app.AppCompatActivity;

public class GameActivity69desc extends AppCompatActivity {

    private Game69.DataBean bean;
    private ImageView iv_left_image;
    private TextView tv_left_text;
    private TextView tv_content_title;
    private ImageView iv_rigth_image;
    private TextView tv_right_text;
    private ImageView iv_game69desc_image;
    private TextView tv_game69desc_desc;
    private TextView tv_game69desc_1;
    private TextView tv_game69desc_2;
    private TextView tv_game69desc_3;
    private TextView tv_game69desc_4;
    private TextView tv_game69desc_5;
    private TextView tv_game69desc_phone;
    private RequestQueue queue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        queue = Volley.newRequestQueue(this);
        setContentView(R.layout.activity_game_activity69desc);
        initView();
        initData();
    }

    //初始化数据
    private void initData() {
        ImageRequest request = new ImageRequest(bean.getImage(), new Response.Listener<Bitmap>() {
            @Override
            public void onResponse(Bitmap bitmap) {
                iv_game69desc_image.setImageBitmap(bitmap);
            }
        }, 0, 0, ImageView.ScaleType.CENTER, Bitmap.Config.ARGB_8888, null);
        queue.add(request);

        tv_game69desc_desc.setText(bean.getContent());
        int grade = bean.getGrade();
        if (grade == 0) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_back_round_black);
        } else if (grade == 1) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_back_round_black);
        } else if (grade == 2) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_back_round_black);
        } else if (grade == 3) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_back_round_black);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_back_round_black);
        } else if (grade == 4) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_back_round_black);

        } else if (grade == 5) {
            tv_game69desc_1.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_2.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_3.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_4.setBackgroundResource(R.drawable.game69_round_blue);
            tv_game69desc_5.setBackgroundResource(R.drawable.game69_round_blue);

        }

        tv_game69desc_phone.setText(bean.getPhone());

        //点击电话号码
        tv_game69desc_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开电话页面
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setData(Uri.parse("tel:"+bean.getPhone()));
                startActivity(intent);

                //启动短信页面
//                Intent intent = new Intent(Intent.ACTION_SENDTO);
//                intent.setData(Uri.parse("smsto:"+bean.getPhone()));
//                intent.putExtra("sms_body" ,"123");
//                startActivity(intent);

                //启动模式页面
//                Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
//                startActivity(intent);

            }
        });


    }


    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void MessageData(Game69.DataBean bean) {
        this.bean = bean;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    private void initView() {
        iv_left_image = (ImageView) findViewById(R.id.iv_left_image);
        tv_left_text = (TextView) findViewById(R.id.tv_left_text);
        tv_content_title = (TextView) findViewById(R.id.tv_content_title);
        iv_rigth_image = (ImageView) findViewById(R.id.iv_rigth_image);
        tv_right_text = (TextView) findViewById(R.id.tv_right_text);

        tv_content_title.setText("详细信息");
        tv_left_text.setVisibility(View.GONE);
        tv_right_text.setVisibility(View.GONE);
        iv_left_image.setImageResource(R.drawable.tiao);
        iv_rigth_image.setVisibility(View.GONE);
        iv_game69desc_image = (ImageView) findViewById(R.id.iv_game69desc_image);
        tv_game69desc_desc = (TextView) findViewById(R.id.tv_game69desc_desc);
        tv_game69desc_1 = (TextView) findViewById(R.id.tv_game69desc_1);
        tv_game69desc_2 = (TextView) findViewById(R.id.tv_game69desc_2);
        tv_game69desc_3 = (TextView) findViewById(R.id.tv_game69desc_3);
        tv_game69desc_4 = (TextView) findViewById(R.id.tv_game69desc_4);
        tv_game69desc_5 = (TextView) findViewById(R.id.tv_game69desc_5);
        tv_game69desc_phone = (TextView) findViewById(R.id.tv_game69desc_phone);
    }
}
